In this step you create materials which provide a directional Gaussian blur effect with four different kernel sizes. To optimize performance you use smaller kernel sizes when possible.
To create materials for the bloom effect:



#version 300 es
precision mediump float;
in vec3 kzPosition;
in vec2 kzTextureCoordinate0;
uniform highp mat4 kzProjectionCameraWorldMatrix;
out mediump vec2 vTexCoord;
void main()
{
vTexCoord = kzTextureCoordinate0;
gl_Position = kzProjectionCameraWorldMatrix * vec4(kzPosition.xyz, 1.0);
}#version 300 es
precision mediump float;
in vec2 vTexCoord;
uniform sampler2D Texture0;
uniform float kzTextureWidth0;
uniform float kzTextureHeight0;
// Defines the direction (x or y axis) along which to apply the blur.
uniform lowp vec2 BlurDirection;
// Determines the strength of the blur.
uniform float BlurRadius;
uniform float BlendIntensity;
// Determines the intensity of the bloom.
uniform float Intensity;
out vec4 outColor;
// Defines the one-dimensional Gaussian kernel with 7 samples.
const float GAUSSIAN_KERNEL[7] = float[7]
(
0.028116, 0.102883, 0.223922, 0.290156, 0.223922, 0.102883, 0.028116
);
vec4 gaussianBlur(mediump vec2 coord, lowp vec2 dir)
{
vec2 texel = vec2(kzTextureWidth0, kzTextureHeight0);
vec4 sum = vec4(0.0);
// Get the original texture coordinate for this fragment.
vec2 tc = coord;
// Get the amount to blur.
float blur = BlurRadius;
// Set the amount of blur in the horizontal direction.
float hstep = dir.x * texel.x * blur;
// Set the amount of blur in the vertical direction.
float vstep = dir.y * texel.y * blur;
// Sample the texture for every fragment as many times as there are samples in the Gaussian kernel.
for(int i = 0; i< GAUSSIAN_KERNEL.length(); i++)
{
float pixelOffset = (float(i) - floor(float(GAUSSIAN_KERNEL.length()) * 0.5));
sum += texture(Texture0, vec2(tc.x + pixelOffset * hstep, tc.y + pixelOffset * vstep)) * GAUSSIAN_KERNEL[i];
}
return sum * Intensity;
}
void main()
{
vec4 retColor = gaussianBlur(vTexCoord, BlurDirection);
outColor = retColor;
}






// Defines the one-dimensional Gaussian kernel with 7 samples.
const float GAUSSIAN_KERNEL[7] = float[7]
(
0.028116, 0.102883, 0.223922, 0.290156, 0.223922, 0.102883, 0.028116
);with// Defines the one-dimensional Gaussian kernel with 9 samples.
const float GAUSSIAN_KERNEL[9] = float[9]
(
0.028532, 0.067234, 0.124009, 0.179044, 0.20236, 0.179044, 0.124009,
0.067234, 0.028532
);Save the shader file.

// Defines the one-dimensional Gaussian kernel with 13 samples.
const float GAUSSIAN_KERNEL[13] = float[13]
(
0.009329, 0.022234, 0.045248, 0.078632, 0.116686, 0.147866, 0.160011, 0.147866,
0.116686, 0.078632, 0.045248, 0.022234, 0.009329
);// Defines the one-dimensional Gaussian kernel with 15 samples.
const float GAUSSIAN_KERNEL[15] = float[15]
(
0.00332, 0.009267, 0.022087, 0.044948, 0.078109, 0.115911, 0.146884, 0.158949,
0.146884, 0.115911, 0.078109, 0.044948, 0.022087, 0.009267, 0.00332
);To learn more about OpenGL ES 3.0, see Using OpenGL ES 3.0 in Kanzi.
To learn more about materials and material types, see Material types and materials.
To learn more about shaders, see Shaders.